import {
  getBuildConfig,
  cjsCompatPlugin,
  lcSecretsPlugin,
  importMapPlugin,
  importConstantsPlugin,
} from "@langchain/build";

export default getBuildConfig({
  entry: [
    "./src/index.ts",
    "./src/chat_models/universal.ts",
    "./src/hub/index.ts",
    "./src/hub/node.ts",
    "./src/load/index.ts",
    "./src/load/serializable.ts",
    "./src/storage/encoder_backed.ts",
    "./src/storage/in_memory.ts",
    "./src/storage/file_system.ts",
  ],
  plugins: [
    cjsCompatPlugin({
      files: ["dist/", "CHANGELOG.md", "README.md", "LICENSE"],
    }),
    lcSecretsPlugin(),
    importMapPlugin({
      extraEntries: [
        {
          modules: ["PromptTemplate"],
          alias: ["prompts", "prompt"],
          path: "@langchain/core/prompts",
        },
        {
          modules: [
            "AIMessage",
            "AIMessageChunk",
            "BaseMessage",
            "BaseMessageChunk",
            "ChatMessage",
            "ChatMessageChunk",
            "FunctionMessage",
            "FunctionMessageChunk",
            "HumanMessage",
            "HumanMessageChunk",
            "SystemMessage",
            "SystemMessageChunk",
            "ToolMessage",
            "ToolMessageChunk",
          ],
          alias: ["schema"],
          path: "@langchain/core/messages",
        },
        {
          modules: [
            "AIMessagePromptTemplate",
            "ChatMessagePromptTemplate",
            "ChatPromptTemplate",
            "HumanMessagePromptTemplate",
            "MessagesPlaceholder",
            "SystemMessagePromptTemplate",
          ],
          alias: ["prompts", "chat"],
          path: "@langchain/core/prompts",
        },
        {
          modules: ["ImagePromptTemplate"],
          alias: ["prompts", "image"],
          path: "@langchain/core/prompts",
        },
        {
          modules: ["PipelinePromptTemplate"],
          alias: ["prompts", "pipeline"],
          path: "@langchain/core/prompts",
        },
        {
          modules: ["StringPromptValue"],
          alias: ["prompts", "base"],
          path: "@langchain/core/prompt_values",
        },
        {
          modules: [
            "RouterRunnable",
            "RunnableAssign",
            "RunnableBinding",
            "RunnableBranch",
            "RunnableEach",
            "RunnableMap",
            "RunnableParallel",
            "RunnablePassthrough",
            "RunnablePick",
            "RunnableRetry",
            "RunnableSequence",
            "RunnableWithFallbacks",
            "RunnableWithMessageHistory",
          ],
          alias: ["schema", "runnable"],
          path: "@langchain/core/runnables",
        },
        {
          modules: ["ChatGenerationChunk", "GenerationChunk"],
          alias: ["schema", "output"],
          path: "@langchain/core/outputs",
        },
      ],
      omitFromImportMap: ["hub/index", "hub/node", "load/index"],
    }),
    importConstantsPlugin({
      entrypoints: [
        "chat_models/universal",
        "cache/file_system",
        "storage/file_system",
        "hub/index",
        "hub/node",
      ],
    }),
  ],
});
